import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { defineConfig } from 'vite'
import mkcert from 'vite-plugin-mkcert'

import loder_pxtovw from './postcss.config.js'
// import fs from 'fs';
// import path from 'path';

import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [mkcert(), vue(), vueJsx()],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
            '~@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    css: {
        postcss: {
            plugins: [loder_pxtovw]
        },
        preprocessorOptions: {
            less: {
                modifyVars: {
                    hack: `true; @import (reference) "${resolve('src/style/var.less')}";`
                },
                javascriptEnabled: true
            }
        }
    },
    build: {
        sourcemap: true, // 或者 'inline' | 'hidden'
    },
    base: './',
    server: {
        host: '0.0.0.0',
        port: 5172, // 服务端口号
        open: true, // 服务启动时是否自动打开浏览器
        cors: true, // 允许跨域
        https: true,// 允许跨域
        // https: {
        //     key: fs.readFileSync(path.resolve(__dirname, 'key.pem')),
        //     cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem')),
        //     rejectUnauthorized: false,
        // },
    }
})
